package com.example.gymmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gymmanagement.Utils.Result;
import com.example.gymmanagement.Utils.StatusCode;
import com.example.gymmanagement.domain.Rent;
import com.example.gymmanagement.domain.User;
import com.example.gymmanagement.service.RentService;
import com.example.gymmanagement.mapper.RentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 13726256113
* @description 针对表【rent】的数据库操作Service实现
* @createDate 2023-06-09 10:57:22
*/
@Service
public class RentServiceImpl extends ServiceImpl<RentMapper, Rent>
    implements RentService{
    @Autowired
    private RentMapper rentMapper;

    @Override
    public boolean insert(Rent rent) {
        return this.rentMapper.insert(rent)>0;
    }

    @Override
    public boolean delete(Integer id) {
        return this.rentMapper.deleteById(id)>0;
    }

    @Override
    public boolean updateRent(Rent rent) {
        return this.rentMapper.updateById(rent)>0;
    }

    @Override
    public Result select(Integer index, Integer size, Rent rent) {
        if (index==null||index==0){
            index=1;
        }
        if (size==null||size==0){
            size=5;
        }
        Page<Rent> pageInfo = new Page(index,size);
        QueryWrapper<Rent> queryWrapper = new QueryWrapper<>();
        if (rent.getRentId()!=null){
            queryWrapper.like("rent_id",rent.getRentId());
        }if (rent.getRentUser()!=null){
            queryWrapper.like("rent_user",rent.getRentUser());
        }if (rent.getRentStart()!=null&&rent.getRentStart().toString()!=""){
            queryWrapper.like("rent_start",rent.getRentStart());
        }if(rent.getRentEnd()!=null&&rent.getRentEnd().toString()!=""){
            queryWrapper.like("rent_end",rent.getRentEnd());
        }if(rent.getRentPrice()!=null){
            queryWrapper.like("rent_price",rent.getRentPrice());
        }if(rent.getRentEquip()!=null){
            queryWrapper.like("rent_equip",rent.getRentEquip());
        }if(rent.getRentField()!=null){
            queryWrapper.like("rent_field",rent.getRentField());
        }if(rent.getRentMatch()!=null){
            queryWrapper.like("rent_match",rent.getRentMatch());
        }if(rent.getRentType()!=null&rent.getRentType()!=""){
            queryWrapper.like("rent_type",rent.getRentType());
        }if(rent.getRentDtail()!=null&&rent.getRentDtail()!=""){
            queryWrapper.like("type_dtial",rent.getRentDtail());
        }if (rent.getRentStatus()!=null&&rent.getRentStatus()!=""){
            queryWrapper.like("rent_status",rent.getRentStatus());
        }
        Page<Rent> rentList = (Page)this.rentMapper.selectPage(pageInfo,queryWrapper);
        Integer code = rentList!=null? StatusCode.GET_OK :StatusCode.GET_ERR;
        String msg= rentList!=null?"查询成功":"查询失败";
        return new Result(code,rentList,msg);
    }
}




